package com.micro.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author micro
 */
public class JsonUtil {
    private static ObjectMapper objectMapper = new ObjectMapper();

    public static <T> String toJsonStr(T t) throws JsonProcessingException {
        return objectMapper.writeValueAsString(t);
    }

    public static <T> T toObject(String jsonStr, Class clazz) throws JsonProcessingException {
        return (T) objectMapper.readValue(jsonStr, clazz);
    }

}
